package com.moji.controller.web;


import com.moji.common.base.ApiResult;
import com.moji.entity.vo.GdAreaVo;
import com.moji.service.GdAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 省市县，三级联动 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2023-10-26
 */
@RestController
@RequestMapping("web/gdArea")
@Api(tags = "省市县三级联动", value = "省市县联查")
public class GdAreaController {

    @Resource
    private GdAreaService gdAreaService;

    /**
     * 查询省份
     * @param
     * @return
     */
    @GetMapping("/findProvince")
    @ApiOperation(value = "查询省份",response = Boolean.class)
    public ApiResult<List<GdAreaVo>> findProvince(){
        try{
            List<GdAreaVo> province = gdAreaService.findProvince();
            return ApiResult.ok(province);
        }catch(Exception e){
            return ApiResult.failed(e.getMessage());
        }
    }

    /**
     * 查询市
     * @param
     * @return
     */
    @GetMapping("/findCity")
    @ApiOperation(value = "查询市",response = Boolean.class)
    public ApiResult<List<GdAreaVo>> findCity(@RequestParam("areaCode")String areaCode){
        try{
            List<GdAreaVo> city = gdAreaService.findCity(areaCode);
            return ApiResult.ok(city);
        }catch(Exception e){
            return ApiResult.failed(e.getMessage());
        }
    }

    /**
     * 查询县区
     * @param
     * @return
     */
    @GetMapping("/findArea")
    @ApiOperation(value = "查询县区",response = Boolean.class)
    public ApiResult<List<GdAreaVo>> findArea(@RequestParam("areaCode")String areaCode){
        try{
            List<GdAreaVo> area = gdAreaService.findArea(areaCode);
            return ApiResult.ok(area);
        }catch(Exception e){
            return ApiResult.failed(e.getMessage());
        }
    }
}

